
***Wars I -International Wars

**** Main Specification
 

use "Temp/Master_5yr.dta" , clear
 *drop if year<1900


 * set graph off to surpress interflex plot (just used for calculated Hainmueller et al's p
 set graphics off
 
  
  
*** Periodicity of war (1) & (2)

 
 
 
 eststo clear
  
 							
 							eststo int_0: reghdfe dtax_non_trade_real  int_war_all_PRIO  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   cr_market_accessXBOEinv X_*  S_g5_unw_alliance_abs   if indep ==0 , absorb(year iso_n) cluster(  iso_n)
														estadd scalar N_true = e(N) + e(num_singletons)

   							eststo int_1: reghdfe dtax_non_trade_real  int_war_all_PRIO  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   cr_market_accessXBOEinv X_*  S_g5_unw_alliance_abs   if indep ==1 , absorb(year iso_n) cluster(  iso_n)
														estadd scalar N_true = e(N) + e(num_singletons)

*** Colonial international wars (3-5)
 
		**** ODA ACCESS
		
		
						* calculate marginal effects and save them and joint pvalues into scalars
							eststo int_m2: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   cr_market_accessXBOEinv X_* i.l1_int_war_all_PRIO##i.S_g5_unw_alliance_abs_binned  if indep == 0 , absorb(year iso_n) cluster(  iso_n)
							tempfile holding
							margins S_g5_unw_alliance_abs_binned  , dydx(l1_int_war_all_PRIO)   post saving(`holding')
							clonevar _m1 = S_g5_unw_alliance_abs_binned
							merge m:1 _m1 using `holding',  keepusing(_margin _pvalue)
							drop _m1 _merge
							
							 
							
							
							egen temp_marg_low=mean(_margin) if S_g5_unw_alliance_abs_binned==0
							egen temp_marg_medium=mean(_margin) if S_g5_unw_alliance_abs_binned==1						
							egen temp_marg_high=mean(_margin) if S_g5_unw_alliance_abs_binned==2
							
							egen temp_p_low=mean(_pvalue) if S_g5_unw_alliance_abs_binned==0
							egen temp_p_medium=mean(_pvalue) if S_g5_unw_alliance_abs_binned==1
							egen temp_p_high=mean(_pvalue) if S_g5_unw_alliance_abs_binned==2					
							
							egen margin_low=mean(temp_marg_low)
							egen margin_medium=mean(temp_marg_medium)
							egen margin_high=mean(temp_marg_high)

							egen p_low=mean(temp_p_low)
							egen p_medium=mean(temp_p_medium)
							egen p_high=mean(temp_p_high)
												
							scalar p_low_s=p_low
							scalar p_medium_s=p_medium
							scalar p_high_s=p_high
	
			
				  
						* Wald statistic for linear vs. binned model
						interflex dtax_non_trade_real l1_int_war_all_PRIO S_g5_unw_alliance_abs libdem_extra_vdem         P_ind_total_f_realshare       cr_market_accessXBOEinv l1_drought_affected_merged l1_gov_change X_* if indep == 0  , fe(year iso_n) cl(iso_n) 
						scalar   l_P_wald =  r(pwald)

						* actual model 					
						eststo int_m2: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   cr_market_accessXBOEinv X_* i.l1_int_war_all_PRIO##i.S_g5_unw_alliance_abs_binned  if indep == 0 , absorb(year iso_n) cluster(  iso_n)
										
							* add statistics to table						
							scalar pval_moderator_medium = (2 * ttail(e(df_r), abs(_b[1.S_g5_unw_alliance_abs_binned] / _se[1.S_g5_unw_alliance_abs_binned]) ) )
							scalar pval_moderator_high = (2 * ttail(e(df_r), abs(_b[2.S_g5_unw_alliance_abs_binned] / _se[2.S_g5_unw_alliance_abs_binned]) ) )
							estadd scalar N_true = e(N) + e(num_singletons)
							estadd scalar P_wald = l_P_wald
							estadd local	moderator_medium  	"`= cond(pval_moderator_medium<0.01,"`:di %5.2f `=_b[1.S_g5_unw_alliance_abs_binned]''***", 	cond(pval_moderator_medium<0.05,"`:di %5.2f `=_b[1.S_g5_unw_alliance_abs_binned]''**", 	cond(pval_moderator_medium<0.1,"`:di %5.2f `=_b[1.S_g5_unw_alliance_abs_binned]''*",  "`:di %5.2f `=_b[1.S_g5_unw_alliance_abs_binned]''")))'"					
							estadd local	moderator_high  	"`= cond(pval_moderator_high<0.01,"`:di %5.2f `=_b[2.S_g5_unw_alliance_abs_binned]''***", 		cond(pval_moderator_high<0.05,"`:di %5.2f `=_b[2.S_g5_unw_alliance_abs_binned]''**", 	cond(pval_moderator_high<0.1,"`:di %5.2f `=_b[2.S_g5_unw_alliance_abs_binned]''*",  "`:di %5.2f `=_b[2.S_g5_unw_alliance_abs_binned]''")))'"
							estadd scalar moderator_medium_se = _se[1.S_g5_unw_alliance_abs_binned] 
							estadd scalar moderator_high_se =  _se[2.S_g5_unw_alliance_abs_binned] 
								

								* add marginal effects with significance stars
								estadd local margin_low		=  	 "`= cond(p_low_s<0.01,"`:di %5.2f `=margin_low''***", 	cond(p_low_s<0.05,"`:di %5.2f `=margin_low''**", 	cond(p_low_s<0.1,"`:di %5.2f `=margin_low''*",  "`:di %5.2f `=margin_low''")))'"					
								estadd local margin_medium		=  	 "`= cond(p_medium_s<0.01,"`:di %5.2f `=margin_medium''***", 	cond(p_medium_s<0.05,"`:di %5.2f `=margin_medium''**", 	cond(p_medium_s<0.1,"`:di %5.2f `=margin_medium''*",  "`:di %5.2f `=margin_medium''")))'"					
								estadd local margin_high	=  	 "`= cond(p_high_s<0.01,"`:di %5.2f `=margin_high''***", 	cond(p_high_s<0.05,"`:di %5.2f `=margin_high''**", 	cond(p_high_s<0.1,"`:di %5.2f `=margin_high''*",  "`:di %5.2f `=margin_high''")))'"					
						
								
									* drop temporary variables
									drop _margin _pvalue temp_marg_low temp_marg_high temp_p_low temp_p_high margin_low margin_high p_low p_high temp_marg_medium temp_p_medium margin_medium p_medium
					
					
			
			
		
		**** CREDIT ACCESS 	
		
						* calculate marginal effects and save them and joint pvalues into scalars
							eststo int_m3: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   S_g5_unw_alliance_abs X_* i.l1_int_war_all_PRIO##i.cr_market_accessXBOEinv_binned  if indep == 0 , absorb(year iso_n) cluster(  iso_n)
							tempfile holding
							margins cr_market_accessXBOEinv_binned  , dydx(l1_int_war_all_PRIO)   post saving(`holding')
							clonevar _m1 = cr_market_accessXBOEinv_binned
							merge m:1 _m1 using `holding',  keepusing(_margin _pvalue)
							drop _m1 _merge
							
							 
							
							
							egen temp_marg_low=mean(_margin) if cr_market_accessXBOEinv_binned==0
							egen temp_marg_medium=mean(_margin) if cr_market_accessXBOEinv_binned==1						
							egen temp_marg_high=mean(_margin) if cr_market_accessXBOEinv_binned==2
							
							egen temp_p_low=mean(_pvalue) if cr_market_accessXBOEinv_binned==0
							egen temp_p_medium=mean(_pvalue) if cr_market_accessXBOEinv_binned==1
							egen temp_p_high=mean(_pvalue) if cr_market_accessXBOEinv_binned==2					
							
							egen margin_low=mean(temp_marg_low)
							egen margin_medium=mean(temp_marg_medium)
							egen margin_high=mean(temp_marg_high)

							egen p_low=mean(temp_p_low)
							egen p_medium=mean(temp_p_medium)
							egen p_high=mean(temp_p_high)
												
							scalar p_low_s=p_low
							scalar p_medium_s=p_medium
							scalar p_high_s=p_high
	
						* Wald statistic for linear vs. binned model
						interflex dtax_non_trade_real l1_int_war_all_PRIO cr_market_accessXBOEinv S_g5_unw_alliance_abs libdem_extra_vdem         P_ind_total_f_realshare        l1_drought_affected_merged l1_gov_change X_* if indep == 0  , fe(year iso_n) cl(iso_n) 
						scalar   l_P_wald =  r(pwald)		 

						* actual model 										
						eststo int_m3: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   S_g5_unw_alliance_abs X_* i.l1_int_war_all_PRIO##i.cr_market_accessXBOEinv_binned  if indep == 0 , absorb(year iso_n) cluster(  iso_n)
	 
							* add statistics to table
							scalar pval_moderator_medium = (2 * ttail(e(df_r), abs(_b[1.cr_market_accessXBOEinv_binned] / _se[1.cr_market_accessXBOEinv_binned]) ) )
							scalar pval_moderator_high = (2 * ttail(e(df_r), abs(_b[2.cr_market_accessXBOEinv_binned] / _se[2.cr_market_accessXBOEinv_binned]) ) )
							estadd scalar N_true = e(N) + e(num_singletons)
							estadd scalar P_wald = l_P_wald
							estadd local	moderator_medium  "`= cond(pval_moderator_medium<0.01,"`:di %5.2f `=_b[1.cr_market_accessXBOEinv_binned]''***", 	cond(pval_moderator_medium<0.05,"`:di %5.2f `=_b[1.cr_market_accessXBOEinv_binned]''**", 	cond(pval_moderator_medium<0.1,"`:di %5.2f `=_b[1.cr_market_accessXBOEinv_binned]''*",  "`:di %5.2f `=_b[1.cr_market_accessXBOEinv_binned]''")))'"					
							estadd local	moderator_high  "`= cond(pval_moderator_high<0.01,"`:di %5.2f `=_b[2.cr_market_accessXBOEinv_binned]''***", 		cond(pval_moderator_high<0.05,"`:di %5.2f `=_b[2.cr_market_accessXBOEinv_binned]''**", 	cond(pval_moderator_high<0.1,"`:di %5.2f `=_b[2.cr_market_accessXBOEinv_binned]''*",  "`:di %5.2f `=_b[2.cr_market_accessXBOEinv_binned]''")))'"
							estadd scalar moderator_medium_se = _se[1.cr_market_accessXBOEinv_binned] 
							estadd scalar moderator_high_se =  _se[2.cr_market_accessXBOEinv_binned]   
							
								* add marginal effects with significance stars
								estadd local margin_low		=  	 "`= cond(p_low_s<0.01,"`:di %5.2f `=margin_low''***", 	cond(p_low_s<0.05,"`:di %5.2f `=margin_low''**", 	cond(p_low_s<0.1,"`:di %5.2f `=margin_low''*",  "`:di %5.2f `=margin_low''")))'"					
								estadd local margin_medium		=  	 "`= cond(p_medium_s<0.01,"`:di %5.2f `=margin_medium''***", 	cond(p_medium_s<0.05,"`:di %5.2f `=margin_medium''**", 	cond(p_medium_s<0.1,"`:di %5.2f `=margin_medium''*",  "`:di %5.2f `=margin_medium''")))'"					
								estadd local margin_high	=  	 "`= cond(p_high_s<0.01,"`:di %5.2f `=margin_high''***", 	cond(p_high_s<0.05,"`:di %5.2f `=margin_high''**", 	cond(p_high_s<0.1,"`:di %5.2f `=margin_high''*",  "`:di %5.2f `=margin_high''")))'"					
						
								
									* drop temporary variables
									drop _margin _pvalue temp_marg_low temp_marg_high temp_p_low temp_p_high margin_low margin_high p_low p_high temp_marg_medium temp_p_medium margin_medium p_medium
					
					
										
					
		**** RESOURCE PRICES 
		
						* calculate marginal effects and save them and joint pvalues into scalars
							eststo int_m4: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  cr_market_accessXBOEinv   S_g5_unw_alliance_abs X_* i.l1_int_war_all_PRIO##i.P_ind_total_f_realshare_binned  if indep == 0 , absorb(year iso_n) cluster(  iso_n)
							tempfile holding
							margins P_ind_total_f_realshare_binned  , dydx(l1_int_war_all_PRIO)   post saving(`holding')
							clonevar _m1 = P_ind_total_f_realshare_binned
							merge m:1 _m1 using `holding',  keepusing(_margin _pvalue)
							drop _m1 _merge
							
							 
							
							
							egen temp_marg_low=mean(_margin) if P_ind_total_f_realshare_binned==0
							egen temp_marg_medium=mean(_margin) if P_ind_total_f_realshare_binned==1						
							egen temp_marg_high=mean(_margin) if P_ind_total_f_realshare_binned==2
							
							egen temp_p_low=mean(_pvalue) if P_ind_total_f_realshare_binned==0
							egen temp_p_medium=mean(_pvalue) if P_ind_total_f_realshare_binned==1
							egen temp_p_high=mean(_pvalue) if P_ind_total_f_realshare_binned==2					
							
							egen margin_low=mean(temp_marg_low)
							egen margin_medium=mean(temp_marg_medium)
							egen margin_high=mean(temp_marg_high)

							egen p_low=mean(temp_p_low)
							egen p_medium=mean(temp_p_medium)
							egen p_high=mean(temp_p_high)
												
							scalar p_low_s=p_low
							scalar p_medium_s=p_medium
							scalar p_high_s=p_high
					
					* Wald statistic for linear vs. binned model
					interflex dtax_non_trade_real l1_int_war_all_PRIO P_ind_total_f_realshare cr_market_accessXBOEinv S_g5_unw_alliance_abs libdem_extra_vdem                 l1_drought_affected_merged l1_gov_change X_* if indep == 0  , fe(year iso_n) cl(iso_n) 
					scalar   l_P_wald =  r(pwald)		 
					
					
					eststo int_m4: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  cr_market_accessXBOEinv   S_g5_unw_alliance_abs X_* i.l1_int_war_all_PRIO##i.P_ind_total_f_realshare_binned  if indep == 0 , absorb(year iso_n) cluster(  iso_n)
					
 
						* add statistics to table
						scalar pval_moderator_medium = (2 * ttail(e(df_r), abs(_b[1.P_ind_total_f_realshare_binned] / _se[1.P_ind_total_f_realshare_binned]) ) )
						scalar pval_moderator_high = (2 * ttail(e(df_r), abs(_b[2.P_ind_total_f_realshare_binned] / _se[2.P_ind_total_f_realshare_binned]) ) )
						estadd scalar N_true = e(N) + e(num_singletons)
						estadd scalar P_wald = l_P_wald
						estadd local	moderator_medium  "`= cond(pval_moderator_medium<0.01,"`:di %5.2f `=_b[1.P_ind_total_f_realshare_binned]''***", 	cond(pval_moderator_medium<0.05,"`:di %5.2f `=_b[1.P_ind_total_f_realshare_binned]''**", 	cond(pval_moderator_medium<0.1,"`:di %5.2f `=_b[1.P_ind_total_f_realshare_binned]''*",  "`:di %5.2f `=_b[1.P_ind_total_f_realshare_binned]''")))'"					
						estadd local	moderator_high  "`= cond(pval_moderator_high<0.01,"`:di %5.2f `=_b[2.P_ind_total_f_realshare_binned]''***", 	cond(pval_moderator_high<0.05,"`:di %5.2f `=_b[2.P_ind_total_f_realshare_binned]''**", 	cond(pval_moderator_high<0.1,"`:di %5.2f `=_b[2.P_ind_total_f_realshare_binned]''*",  "`:di %5.2f `=_b[2.P_ind_total_f_realshare_binned]''")))'"
						estadd scalar moderator_medium_se = _se[1.P_ind_total_f_realshare_binned] 
						estadd scalar moderator_high_se =  _se[2.P_ind_total_f_realshare_binned] 
						
 					
								* add marginal effects with significance stars
								estadd local margin_low		=  	 "`= cond(p_low_s<0.01,"`:di %5.2f `=margin_low''***", 	cond(p_low_s<0.05,"`:di %5.2f `=margin_low''**", 	cond(p_low_s<0.1,"`:di %5.2f `=margin_low''*",  "`:di %5.2f `=margin_low''")))'"					
								estadd local margin_medium		=  	 "`= cond(p_medium_s<0.01,"`:di %5.2f `=margin_medium''***", 	cond(p_medium_s<0.05,"`:di %5.2f `=margin_medium''**", 	cond(p_medium_s<0.1,"`:di %5.2f `=margin_medium''*",  "`:di %5.2f `=margin_medium''")))'"					
								estadd local margin_high	=  	 "`= cond(p_high_s<0.01,"`:di %5.2f `=margin_high''***", 	cond(p_high_s<0.05,"`:di %5.2f `=margin_high''**", 	cond(p_high_s<0.1,"`:di %5.2f `=margin_high''*",  "`:di %5.2f `=margin_high''")))'"					
						
											
		
									* drop temporary variables
									drop _margin _pvalue temp_marg_low temp_marg_high temp_p_low temp_p_high margin_low margin_high p_low p_high temp_marg_medium temp_p_medium margin_medium p_medium
					
				  
 
*** Independent international wars (6-8)
 
   
		**** ODA ACCESS

						* calculate marginal effects and save them and joint pvalues into scalars
							eststo sov_int_m2: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   cr_market_accessXBOEinv X_* i.l1_int_war_all_PRIO##i.S_g5_unw_alliance_abs_binned  if indep == 1, absorb(year iso_n) cluster(  iso_n)
							tempfile holding
							margins S_g5_unw_alliance_abs_binned  , dydx(l1_int_war_all_PRIO)   post saving(`holding')
							clonevar _m1 = S_g5_unw_alliance_abs_binned
							merge m:1 _m1 using `holding',  keepusing(_margin _pvalue)
							drop _m1 _merge
							
							 
							
							
							egen temp_marg_low=mean(_margin) if S_g5_unw_alliance_abs_binned==0
							egen temp_marg_medium=mean(_margin) if S_g5_unw_alliance_abs_binned==1						
							egen temp_marg_high=mean(_margin) if S_g5_unw_alliance_abs_binned==2
							
							egen temp_p_low=mean(_pvalue) if S_g5_unw_alliance_abs_binned==0
							egen temp_p_medium=mean(_pvalue) if S_g5_unw_alliance_abs_binned==1
							egen temp_p_high=mean(_pvalue) if S_g5_unw_alliance_abs_binned==2					
							
							egen margin_low=mean(temp_marg_low)
							egen margin_medium=mean(temp_marg_medium)
							egen margin_high=mean(temp_marg_high)

							egen p_low=mean(temp_p_low)
							egen p_medium=mean(temp_p_medium)
							egen p_high=mean(temp_p_high)
												
							scalar p_low_s=p_low
							scalar p_medium_s=p_medium
							scalar p_high_s=p_high
							
							
							
					* Wald statistic for linear vs. binned model
					interflex dtax_non_trade_real l1_int_war_all_PRIO S_g5_unw_alliance_abs libdem_extra_vdem         P_ind_total_f_realshare       cr_market_accessXBOEinv l1_drought_affected_merged l1_gov_change X_* if indep == 1  , fe(year iso_n) cl(iso_n) 
					scalar   l_P_wald =  r(pwald)

					* actual model 					
					eststo sov_int_m2: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   cr_market_accessXBOEinv X_* i.l1_int_war_all_PRIO##i.S_g5_unw_alliance_abs_binned  if indep == 1, absorb(year iso_n) cluster(  iso_n)
									
						* add statistics to table						
						scalar pval_moderator_medium = (2 * ttail(e(df_r), abs(_b[1.S_g5_unw_alliance_abs_binned] / _se[1.S_g5_unw_alliance_abs_binned]) ) )
						scalar pval_moderator_high = (2 * ttail(e(df_r), abs(_b[2.S_g5_unw_alliance_abs_binned] / _se[2.S_g5_unw_alliance_abs_binned]) ) )
						estadd scalar N_true = e(N) + e(num_singletons)
						estadd scalar P_wald = l_P_wald
						estadd local	moderator_medium  	"`= cond(pval_moderator_medium<0.01,"`:di %5.2f `=_b[1.S_g5_unw_alliance_abs_binned]''***", 	cond(pval_moderator_medium<0.05,"`:di %5.2f `=_b[1.S_g5_unw_alliance_abs_binned]''**", 	cond(pval_moderator_medium<0.1,"`:di %5.2f `=_b[1.S_g5_unw_alliance_abs_binned]''*",  "`:di %5.2f `=_b[1.S_g5_unw_alliance_abs_binned]''")))'"					
						estadd local	moderator_high  	"`= cond(pval_moderator_high<0.01,"`:di %5.2f `=_b[2.S_g5_unw_alliance_abs_binned]''***", 		cond(pval_moderator_high<0.05,"`:di %5.2f `=_b[2.S_g5_unw_alliance_abs_binned]''**", 	cond(pval_moderator_high<0.1,"`:di %5.2f `=_b[2.S_g5_unw_alliance_abs_binned]''*",  "`:di %5.2f `=_b[2.S_g5_unw_alliance_abs_binned]''")))'"
						estadd scalar moderator_medium_se = _se[1.S_g5_unw_alliance_abs_binned] 
						estadd scalar moderator_high_se =  _se[2.S_g5_unw_alliance_abs_binned] 
							

		
								* add marginal effects with significance stars
								estadd local margin_low		=  	 "`= cond(p_low_s<0.01,"`:di %5.2f `=margin_low''***", 	cond(p_low_s<0.05,"`:di %5.2f `=margin_low''**", 	cond(p_low_s<0.1,"`:di %5.2f `=margin_low''*",  "`:di %5.2f `=margin_low''")))'"					
								estadd local margin_medium		=  	 "`= cond(p_medium_s<0.01,"`:di %5.2f `=margin_medium''***", 	cond(p_medium_s<0.05,"`:di %5.2f `=margin_medium''**", 	cond(p_medium_s<0.1,"`:di %5.2f `=margin_medium''*",  "`:di %5.2f `=margin_medium''")))'"					
								estadd local margin_high	=  	 "`= cond(p_high_s<0.01,"`:di %5.2f `=margin_high''***", 	cond(p_high_s<0.05,"`:di %5.2f `=margin_high''**", 	cond(p_high_s<0.1,"`:di %5.2f `=margin_high''*",  "`:di %5.2f `=margin_high''")))'"					
						
											
		
									* drop temporary variables
									drop _margin _pvalue temp_marg_low temp_marg_high temp_p_low temp_p_high margin_low margin_high p_low p_high temp_marg_medium temp_p_medium margin_medium p_medium
		
		
		
		
		**** CREDIT ACCESS 
		
						* calculate marginal effects and save them and joint pvalues into scalars
							eststo sov_int_m3: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   S_g5_unw_alliance_abs X_* i.l1_int_war_all_PRIO##i.cr_market_accessXBOEinv_binned  if indep == 1 , absorb(year iso_n) cluster(  iso_n)
							tempfile holding
							margins cr_market_accessXBOEinv_binned  , dydx(l1_int_war_all_PRIO)  noestimcheck  post saving(`holding') 
							clonevar _m1 = cr_market_accessXBOEinv_binned
							merge m:1 _m1 using `holding',  keepusing(_margin _pvalue)
							drop _m1 _merge
							
							 
							
							
							egen temp_marg_low=mean(_margin) if cr_market_accessXBOEinv_binned==0
							egen temp_marg_medium=mean(_margin) if cr_market_accessXBOEinv_binned==1						
							egen temp_marg_high=mean(_margin) if cr_market_accessXBOEinv_binned==2
							
							egen temp_p_low=mean(_pvalue) if cr_market_accessXBOEinv_binned==0
							egen temp_p_medium=mean(_pvalue) if cr_market_accessXBOEinv_binned==1
							egen temp_p_high=mean(_pvalue) if cr_market_accessXBOEinv_binned==2					
							
							egen margin_low=mean(temp_marg_low)
							egen margin_medium=mean(temp_marg_medium)
							egen margin_high=mean(temp_marg_high)

							egen p_low=mean(temp_p_low)
							egen p_medium=mean(temp_p_medium)
							egen p_high=mean(temp_p_high)
												
							scalar p_low_s=p_low
							scalar p_medium_s=p_medium
							scalar p_high_s=p_high
	
					* Wald statistic for linear vs. binned model
					interflex dtax_non_trade_real l1_int_war_all_PRIO cr_market_accessXBOEinv S_g5_unw_alliance_abs libdem_extra_vdem         P_ind_total_f_realshare        l1_drought_affected_merged l1_gov_change X_* if indep ==1  , fe(year iso_n) cl(iso_n) 
					scalar   l_P_wald =  r(pwald)		 

					* actual model 										
					eststo sov_int_m3: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  P_ind_total_f_realshare   S_g5_unw_alliance_abs X_* i.l1_int_war_all_PRIO##i.cr_market_accessXBOEinv_binned  if indep == 1 , absorb(year iso_n) cluster(  iso_n)
 
 						* add statistics to table
						scalar pval_moderator_medium = (2 * ttail(e(df_r), abs(_b[1.cr_market_accessXBOEinv_binned] / _se[1.cr_market_accessXBOEinv_binned]) ) )
						scalar pval_moderator_high = (2 * ttail(e(df_r), abs(_b[2.cr_market_accessXBOEinv_binned] / _se[2.cr_market_accessXBOEinv_binned]) ) )
						estadd scalar N_true = e(N) + e(num_singletons)
						estadd scalar P_wald = l_P_wald
						estadd local	moderator_medium  "`= cond(pval_moderator_medium<0.01,"`:di %5.2f `=_b[1.cr_market_accessXBOEinv_binned]''***", 	cond(pval_moderator_medium<0.05,"`:di %5.2f `=_b[1.cr_market_accessXBOEinv_binned]''**", 	cond(pval_moderator_medium<0.1,"`:di %5.2f `=_b[1.cr_market_accessXBOEinv_binned]''*",  "`:di %5.2f `=_b[1.cr_market_accessXBOEinv_binned]''")))'"					
						*estadd local	moderator_high  "`= cond(pval_moderator_high<0.01,"`:di %5.2f `=_b[2.cr_market_accessXBOEinv_binned]''***", 		cond(pval_moderator_high<0.05,"`:di %5.2f `=_b[2.cr_market_accessXBOEinv_binned]''**", 	cond(pval_moderator_high<0.1,"`:di %5.2f `=_b[2.cr_market_accessXBOEinv_binned]''*",  "`:di %5.2f `=_b[2.cr_market_accessXBOEinv_binned]''")))'"
						estadd local moderator_high =   "-" // moderator coeffiecent not identified and shows as 0 in RTF table otherwise
						estadd scalar moderator_medium_se = _se[1.cr_market_accessXBOEinv_binned] 
						estadd scalar moderator_high_se =  _se[2.cr_market_accessXBOEinv_binned] 
						
								* add marginal effects with significance stars
								estadd local margin_low		=  	 "`= cond(p_low_s<0.01,"`:di %5.2f `=margin_low''***", 	cond(p_low_s<0.05,"`:di %5.2f `=margin_low''**", 	cond(p_low_s<0.1,"`:di %5.2f `=margin_low''*",  "`:di %5.2f `=margin_low''")))'"					
								estadd local margin_medium		=  	 "`= cond(p_medium_s<0.01,"`:di %5.2f `=margin_medium''***", 	cond(p_medium_s<0.05,"`:di %5.2f `=margin_medium''**", 	cond(p_medium_s<0.1,"`:di %5.2f `=margin_medium''*",  "`:di %5.2f `=margin_medium''")))'"					
								estadd local margin_high	=  	 "`= cond(p_high_s<0.01,"`:di %5.2f `=margin_high''***", 	cond(p_high_s<0.05,"`:di %5.2f `=margin_high''**", 	cond(p_high_s<0.1,"`:di %5.2f `=margin_high''*",  "`:di %5.2f `=margin_high''")))'"					
						
											
		
									* drop temporary variables
									drop _margin _pvalue temp_marg_low temp_marg_high temp_p_low temp_p_high margin_low margin_high p_low p_high temp_marg_medium temp_p_medium margin_medium p_medium
		
		
									
					
		**** RESOURCE PRICES 
				
						* calculate marginal effects and save them and joint pvalues into scalars
							eststo sov_int_m4: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  cr_market_accessXBOEinv   S_g5_unw_alliance_abs X_* i.l1_int_war_all_PRIO##i.P_ind_total_f_realshare_binned  if indep == 1 , absorb(year iso_n) cluster(  iso_n)
							tempfile holding
							margins P_ind_total_f_realshare_binned  , dydx(l1_int_war_all_PRIO)   post saving(`holding')
							clonevar _m1 = P_ind_total_f_realshare_binned
							merge m:1 _m1 using `holding',  keepusing(_margin _pvalue)
							drop _m1 _merge
							
							 
							
							
							egen temp_marg_low=mean(_margin) if P_ind_total_f_realshare_binned==0
							egen temp_marg_medium=mean(_margin) if P_ind_total_f_realshare_binned==1						
							egen temp_marg_high=mean(_margin) if P_ind_total_f_realshare_binned==2
							
							egen temp_p_low=mean(_pvalue) if P_ind_total_f_realshare_binned==0
							egen temp_p_medium=mean(_pvalue) if P_ind_total_f_realshare_binned==1
							egen temp_p_high=mean(_pvalue) if P_ind_total_f_realshare_binned==2					
							
							egen margin_low=mean(temp_marg_low)
							egen margin_medium=mean(temp_marg_medium)
							egen margin_high=mean(temp_marg_high)

							egen p_low=mean(temp_p_low)
							egen p_medium=mean(temp_p_medium)
							egen p_high=mean(temp_p_high)
												
							scalar p_low_s=p_low
							scalar p_medium_s=p_medium
							scalar p_high_s=p_high
					
					* Wald statistic for linear vs. binned model
					interflex dtax_non_trade_real l1_int_war_all_PRIO P_ind_total_f_realshare cr_market_accessXBOEinv S_g5_unw_alliance_abs libdem_extra_vdem                 l1_drought_affected_merged l1_gov_change X_* if indep == 1 , fe(year iso_n) cl(iso_n) 
					scalar   l_P_wald =  r(pwald)		 
					
					
					eststo sov_int_m4: reghdfe dtax_non_trade_real  libdem_extra_vdem    	l1_drought_affected_merged	l1_gov_change  cr_market_accessXBOEinv   S_g5_unw_alliance_abs X_* i.l1_int_war_all_PRIO##i.P_ind_total_f_realshare_binned  if indep == 1 , absorb(year iso_n) cluster(  iso_n)
					
 
						* add statistics to table
						scalar pval_moderator_medium = (2 * ttail(e(df_r), abs(_b[1.P_ind_total_f_realshare_binned] / _se[1.P_ind_total_f_realshare_binned]) ) )
						scalar pval_moderator_high = (2 * ttail(e(df_r), abs(_b[2.P_ind_total_f_realshare_binned] / _se[2.P_ind_total_f_realshare_binned]) ) )
						estadd scalar N_true = e(N) + e(num_singletons)
						estadd scalar P_wald = l_P_wald
						estadd local	moderator_medium  "`= cond(pval_moderator_medium<0.01,"`:di %5.2f `=_b[1.P_ind_total_f_realshare_binned]''***", 	cond(pval_moderator_medium<0.05,"`:di %5.2f `=_b[1.P_ind_total_f_realshare_binned]''**", 	cond(pval_moderator_medium<0.1,"`:di %5.2f `=_b[1.P_ind_total_f_realshare_binned]''*",  "`:di %5.2f `=_b[1.P_ind_total_f_realshare_binned]''")))'"					
						estadd local	moderator_high  "`= cond(pval_moderator_high<0.01,"`:di %5.2f `=_b[2.P_ind_total_f_realshare_binned]''***", 	cond(pval_moderator_high<0.05,"`:di %5.2f `=_b[2.P_ind_total_f_realshare_binned]''**", 	cond(pval_moderator_high<0.1,"`:di %5.2f `=_b[2.P_ind_total_f_realshare_binned]''*",  "`:di %5.2f `=_b[2.P_ind_total_f_realshare_binned]''")))'"
						estadd scalar moderator_medium_se = _se[1.P_ind_total_f_realshare_binned] 
						estadd scalar moderator_high_se =  _se[2.P_ind_total_f_realshare_binned] 
						
 					
								* add marginal effects with significance stars
								estadd local margin_low		=  	 "`= cond(p_low_s<0.01,"`:di %5.2f `=margin_low''***", 	cond(p_low_s<0.05,"`:di %5.2f `=margin_low''**", 	cond(p_low_s<0.1,"`:di %5.2f `=margin_low''*",  "`:di %5.2f `=margin_low''")))'"					
								estadd local margin_medium		=  	 "`= cond(p_medium_s<0.01,"`:di %5.2f `=margin_medium''***", 	cond(p_medium_s<0.05,"`:di %5.2f `=margin_medium''**", 	cond(p_medium_s<0.1,"`:di %5.2f `=margin_medium''*",  "`:di %5.2f `=margin_medium''")))'"					
								estadd local margin_high	=  	 "`= cond(p_high_s<0.01,"`:di %5.2f `=margin_high''***", 	cond(p_high_s<0.05,"`:di %5.2f `=margin_high''**", 	cond(p_high_s<0.1,"`:di %5.2f `=margin_high''*",  "`:di %5.2f `=margin_high''")))'"					
						
											
		
									* drop temporary variables
									drop _margin _pvalue temp_marg_low temp_marg_high temp_p_low temp_p_high margin_low margin_high p_low p_high temp_marg_medium temp_p_medium margin_medium p_medium
		
							
	
		
* export results
		esttab    int_0 int_1 int_m2 int_m3 int_m4   sov_int_m2 sov_int_m3 sov_int_m4    using "Output/Tables/Main/Table4.rtf", replace style(tex) cells(b(star fmt(2)) se(par fmt(2)) P_wald(  fmt(2))) stats(margin_low margin_medium margin_high moderator_medium   moderator_high    N_true r2_a    P_wald, fmt(2  2 2  2  2  0 2 2   ) labels("Marginal effect (moderator low)"    "Marginal effect (moderator medium)" "Marginal effect (moderator high)" "Moderator - medium"   "Moderator - high"   "Observations" "Adjusted $R^2$" "Xu's Wald test")) legend label   starlevels(* 0.1 ** 0.05 *** 0.01) drop(_cons  libdem_extra_vdem   l1_drought_affected_merged l1_gov_change P_ind_total_f_realshare  S_g5_unw_alliance_abs   cr_market_accessXBOEinv 	X_*)
		esttab    int_0 int_1   int_m2 int_m3 int_m4   sov_int_m2 sov_int_m3 sov_int_m4    using "Output/Tables/Main/Table4.tex", replace style(tex) cells(b(star fmt(2)) se(par fmt(2)) P_wald(  fmt(2))) stats(margin_low margin_medium margin_high moderator_medium   moderator_high    N_true r2_a    P_wald, fmt(2 2  2  2  2  0 2 2   ) labels("Marginal effect (moderator low)"    "Marginal effect (moderator medium)" "Marginal effect (moderator high)" "Moderator - medium"   "Moderator - high"   "Observations" "Adjusted $R^2$" "Xu's Wald test")) legend label   starlevels(* 0.1 ** 0.05 *** 0.01) drop(_cons  libdem_extra_vdem   l1_drought_affected_merged l1_gov_change P_ind_total_f_realshare  S_g5_unw_alliance_abs   cr_market_accessXBOEinv 	X_*)
 
		set graphics on

 
